#include <iostream>
using namespace std;

// 抽象类 : 有纯虚函数的类

class Tree {
public:
    virtual void show()
    {
        cout << "树是非常重要的一种数据结构！" << endl;
    }
    virtual ~Tree() {
        cout << "析构一个树对象!" << endl;
    }
};

class Binary_Tree : public Tree {
public:
    virtual void show() override {
        cout << "二叉树每个结点至多有两棵子树，且有左右之分！" << endl;
    }
    virtual ~Binary_Tree() override {
        cout << "析构一个二叉树对象!" << endl;
    }
};

class Binary_Sort_Tree : public Binary_Tree {
public:
    virtual void show() override {
        cout << "二叉排序树首先是一颗二叉树！" << endl;
        cout << "如果左子树不空，左子树小于根节点！" << endl;
        cout << "如果右子树不空，右子树大于根节点！" << endl;
    }
    virtual ~Binary_Sort_Tree() override {
        cout << "析构一个二叉排序树对象!" << endl;
    }
};


void showWithReference(Tree& tree) {
    tree.show(); // 动态绑定
}

void showWithPointer(Tree* tree) {
    if (tree) {
        tree->show(); // 动态绑定
    }
}


int main() {
    Tree* tree1 = new Binary_Tree();
    tree1->show();
    delete tree1;

    Tree* tree2 = new Binary_Sort_Tree();
    tree2->show();
    delete tree2;

    return 0;
}

// 析构顺序： 从派生类到基类，逐层析构。
//构造顺序： 与析构相反，构造函数从基类到派生类依次调用。
